package com.stylefeng.guns.poi.pl.tablePolicy;

import java.util.List;

import org.apache.poi.xwpf.usermodel.XWPFTable;

import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.policy.DynamicTableRenderPolicy;
import com.deepoove.poi.policy.MiniTableRenderPolicy;

public class CommonDetailTable extends DynamicTableRenderPolicy {

    // 
    private int startRow = 0;

    private boolean flashback = true; //默认倒叙展示 从最后一项开始
    /**
     * 明细在
     * @param startRow
     */
    public CommonDetailTable(int startRow) {
    	this.startRow = startRow;
	}
    
    /**
     * 明细在
     * @param startRow
     */
    public CommonDetailTable(int startRow, boolean flashback) {
    	this.startRow = startRow;
    	this.flashback = flashback;
	}
    
	@Override
	public void render(XWPFTable table, Object data) {
		if (null == data) return;
		List<RowRenderData> datas = (List<RowRenderData>) data;
		if (null != datas) {
			int z = 0;
			if(flashback){
				for (int i = datas.size() - 1; i >= 0; i--, z++) {
					MiniTableRenderPolicy.renderRow(table, startRow + z, datas.get(i));
				}
			}else{
				for (int i = 0; i < datas.size(); i ++){
					MiniTableRenderPolicy.renderRow(table, startRow + i, datas.get(i));
				}
			}
			
		}
	}
}
